﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;

namespace WMI.NET.CIM
{
    /// <summary>
    /// The CIM_VideoController class represents the capabilities and management of the video controller.
    /// </summary>
    public class CIM_VideoController : CIM_Controller
    {

        private UInt16[] _AcceleratorCapabilities;
        private string[] _CapabilityDescriptions;
        private Nullable<UInt32> _CurrentBitsPerPixel;
        private Nullable<UInt32> _CurrentHorizontalResolution;
        private Nullable<UInt64> _CurrentNumberOfColors;
        private Nullable<UInt32> _CurrentNumberOfColumns;
        private Nullable<UInt32> _CurrentNumberOfRows;
        private Nullable<UInt32> _CurrentRefreshRate;
        private Nullable<UInt16> _CurrentScanMode;
        private Nullable<UInt32> _CurrentVerticalResolution;
        private Nullable<UInt32> _MaxMemorySupported;
        private Nullable<UInt32> _MaxRefreshRate;
        private Nullable<UInt32> _MinRefreshRate;
        private Nullable<UInt32> _NumberOfVideoPages;
        private Nullable<UInt16> _VideoMemoryType;
        private string _VideoProcessor;

        /// <summary>
        /// Graphics and 3-D capabilities of the video controller.
        /// </summary>
        public UInt16[] AcceleratorCapabilities { get { return _AcceleratorCapabilities; } } //TODO enum

        /// <summary>
        /// Free-form strings that provide detailed descriptions for the video accelerator features indicated in the AcceleratorCapabilities array.
        /// Note   Each entry of this array is related to the entry in the AcceleratorCapabilities array that is located at the same index.
        /// </summary>
        public string[] CapabilityDescriptions { get { return _CapabilityDescriptions; } }

        /// <summary>
        /// Number of bits used to display each pixel.
        /// </summary>
        public Nullable<UInt32> CurrentBitsPerPixel { get { return _CurrentBitsPerPixel; } }

        /// <summary>
        /// Current number of horizontal pixels.
        /// </summary>
        public Nullable<UInt32> CurrentHorizontalResolution { get { return _CurrentHorizontalResolution; } }

        /// <summary>
        /// Number of colors supported at the current resolution.
        /// </summary>
        public Nullable<UInt64> CurrentNumberOfColors { get { return _CurrentNumberOfColors; } }

        /// <summary>
        /// If in character mode, number of columns for the video controller; otherwise, enter 0.
        /// </summary>
        public Nullable<UInt32> CurrentNumberOfColumns { get { return _CurrentNumberOfColumns; } }

        /// <summary>
        /// If in character mode, number of rows for the video controller; otherwise, enter 0.
        /// </summary>
        public Nullable<UInt32> CurrentNumberOfRows { get { return _CurrentNumberOfRows; } }

        /// <summary>
        /// Current refresh rate, in hertz.
        /// </summary>
        public Nullable<UInt32> CurrentRefreshRate { get { return _CurrentRefreshRate; } }

        /// <summary>
        /// Current scan mode. 
        /// </summary>
        public Nullable<UInt16> CurrentScanMode { get { return _CurrentScanMode; } }

        /// <summary>
        /// Current number of vertical pixels.
        /// </summary>
        public Nullable<UInt32> CurrentVerticalResolution { get { return _CurrentVerticalResolution; } }

        /// <summary>
        /// Maximum amount of memory supported, in bytes.
        /// </summary>
        public Nullable<UInt32> MaxMemorySupported { get { return _MaxMemorySupported; } }

        /// <summary>
        /// Maximum refresh rate of the video controller, in hertz.
        /// </summary>
        public Nullable<UInt32> MaxRefreshRate { get { return _MaxRefreshRate; } }

        /// <summary>
        /// Minimum refresh rate of the video controller, in hertz.
        /// </summary>
        public Nullable<UInt32> MinRefreshRate { get { return _MinRefreshRate; } }

        /// <summary>
        /// Number of video pages supported given the current resolutions and available memory.
        /// </summary>
        public Nullable<UInt32> NumberOfVideoPages { get { return _NumberOfVideoPages; } }

        /// <summary>
        /// Type of video memory.
        /// </summary>
        public Nullable<UInt16> VideoMemoryType { get { return _VideoMemoryType; } } //TODO enum

        /// <summary>
        /// Free-form string that describes the video processor or controller.
        /// </summary>
        public string VideoProcessor { get { return _VideoProcessor; } }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="mbo"></param>
        public CIM_VideoController(ManagementBaseObject mbo)
            :base(mbo)
        {
            _AcceleratorCapabilities = mbo.GetUshortValueArray("AcceleratorCapabilities");
            _CapabilityDescriptions = mbo.GetStringValueArray("CapabilityDescriptions");
            _CurrentBitsPerPixel = mbo.GetUIntValue("CurrentBitsPerPixel");
            _CurrentHorizontalResolution = mbo.GetUIntValue("CurrentHorizontalResolution");
            _CurrentNumberOfColors = mbo.GetUlongValue("CurrentNumberOfColors");
            _CurrentNumberOfColumns = mbo.GetUIntValue("CurrentNumberOfColumns");
            _CurrentNumberOfRows = mbo.GetUIntValue("CurrentNumberOfRows");
            _CurrentRefreshRate = mbo.GetUIntValue("CurrentRefreshRate");
            _CurrentScanMode = mbo.GetUshortValue("CurrentScanMode");
            _CurrentVerticalResolution = mbo.GetUIntValue("CurrentVerticalResolution");
            _MaxMemorySupported = mbo.GetUIntValue("MaxMemorySupported");
            _MaxRefreshRate = mbo.GetUIntValue("MaxRefreshRate");
            _MinRefreshRate = mbo.GetUIntValue("MinRefreshRate");
            _NumberOfVideoPages = mbo.GetUIntValue("NumberOfVideoPages");
            _VideoMemoryType = mbo.GetUshortValue("VideoMemoryType");
            _VideoProcessor = mbo.GetStringValue("VideoProcessor");
        }

    }
}
